package com.aki.ai_property.controller;

import com.aki.ai_property.entity.User;
import com.aki.ai_property.service.intf.UserService;
import com.aki.ai_property.vo.PageBean;
import com.aki.ai_property.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * ━━━━━━永无BUG!━━━━━━
 *
 * @author AKI
 * @date 2022/8/25
 */
@RestController
@RequestMapping("/api/user/")
public class UserController {
    /**
     * 注入
     */
    @Autowired
    private UserService service;

    /**
     * 登录
     * @param user
     * @param request
     * @return
     */
    @PostMapping("login.do")
    public Result login(User user, HttpServletRequest request){

       return service.login(user,request.getSession());

    }
    /**
     * 注册
     * @param user
     * @return
     */
    @PostMapping("register.do")
    public Result register(User user){
       return service.save(user);
    }

    @GetMapping("all.ao")
    public Result all(){
        return service.all();
    }

    @PostMapping("delete.do")
    public Result delete(Integer id){
        return service.delete(id);
    }
    @GetMapping("page.do")
    public PageBean page(String name, int page, int limit){
        return service.selectPage(name,page,limit);
    }
}

